package com.atguigu.dao.impl;

import com.atguigu.dao.VhostDao;
import com.atguigu.pojo.Vhost;
import java.util.List;

public class VhostDaoImpl extends BaseDao implements VhostDao {
    @Override
    public Integer addVhost(Vhost vhost) {
        System.out.println("VhostDaoImpl程序在["+Thread.currentThread().getName()+"]线程中");
        String sql="insert into t_vhost(`vhostId`,`serviceId`,`port`) values(?,?,?);";
        return update(sql,vhost.getVhostId(),vhost.getServiceId(),vhost.getPort());
    }

    @Override
    public Integer deleteVhostByVhostId(String vhostId) {
        String sql = "delete from t_vhost where vhostId=?";
        return update(sql, vhostId);
    }

    @Override
    public List<Vhost> queryVhostsByServiceId(String serviceId) {
        String sql ="select `vhostId`,`serviceId`,`port` from t_vhost where serviceId = ?";
        return queryForList(Vhost.class,sql,serviceId);
    }

    @Override
    public List<Vhost> queryVhostsByServiceIdAndPort(String serviceId, String port) {
        String sql ="select `vhostId`,`serviceId`,`port` from t_vhost where serviceId = ? and port= ?";
        return queryForList(Vhost.class,sql,serviceId,port);
    }
}
